package com.ebeijia.web.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ebeijia.mybatis.pojo.ApplyDetailInfo;
import com.ebeijia.mybatis.pojo.ApplyInfo;
import com.ebeijia.service.user.ApplyDetailInfoService;
import com.ebeijia.service.user.ApplyInfoService;
import com.ebeijia.util.CheckIdCardUtil;
import com.ebeijia.util.LoggerUtil;
import com.ebeijia.web.ResponseMessage;

@Controller
@RequestMapping("/applyInfo")
public class ApplyInfoController {

	@Autowired
	private ApplyInfoService applyInfoService;

	/**
	 * 进度查询 
	 */
	@RequestMapping("/businessRepair")
	@ResponseBody
	public ResponseMessage BusinessRepair(ApplyInfo apply) {
			
			List<ApplyInfo> list=applyInfoService.queryApplyProgress(apply.getApplyUserId());
			if (list!=null) {
				return ResponseMessage.success(list);	
			} else {
				return ResponseMessage.error("0001", "用户申请失败");
			}
		}
	/**
	 * 故障报修  
	 */
	@RequestMapping("/checkRepair")
	@ResponseBody
	public ResponseMessage checkRepair(ApplyInfo apply,HttpServletRequest request) {
		String userId=request.getParameter("userId");
		String homeNo=request.getParameter("homeUserNo");
		//自动生成唯一编号 
		int r1=(int)(Math.random()*(10));//产生2个0-9的随机数
		int r2=(int)(Math.random()*(10));
		long now = System.currentTimeMillis();//一个13位的时间戳
		String paymentID =String.valueOf(r1)+String.valueOf(r2)+String.valueOf(now);
		apply.setApplyNo(paymentID);
		apply.setApplyType("02");//02 代表故障报修  03 水表检修 
		apply.setApplyDate(new Date());
		apply.setApplyStatus("01");//01 代表未受理  02  代表已受理   03代表 已完结
		apply.setApplyUserId(homeNo);
		int count =applyInfoService.insert(apply);
			if (count!=0) {
				return ResponseMessage.error("0000","用户报修成功");	
			} else {
				return ResponseMessage.error("0001", "用户报修失败");
			}
		}

}
